package ai.people.netmon.telegram.config;

import java.io.File;

/**
 * @description:
 * @author: Xing.Wei
 * @time: 2021-05-27 10:44
 */
public class RemoveFile {
    public static void main(String[] args) {
        File f = new File("C:\\btc\\nm-service\\trunk");
        for (File fs : f.listFiles()) {
            if (fs.getName().equals(".svn")) {
                continue;
            }
            listFile(fs);
        }

        for (File fs : f.listFiles()) {
            if (fs.getName().equals(".svn")) {
                continue;
            }
            File testFile = new File(fs, "src/test/java");
            if (testFile.exists()) {
                for (File dfs : testFile.listFiles()) {
                    listDelete(dfs);
                }
            }
        }
    }

    public static void listFile(File f) {
        String name = f.getName();
        if (f.isDirectory()) {
            if (name.equals("target") || name.equals("logs")) {
//                System.out.println(f.getAbsolutePath());
                listDelete(f);
            } else {

                for (File fs : f.listFiles()) {
                    listFile(fs);
                }
            }
        } else {
            if (name.startsWith("nm") && name.endsWith(".iml")) {
//                System.out.println(f.getAbsolutePath());
                f.delete();
            }
        }
    }

    public static void listDelete(File f) {
        if (f.isDirectory()) {
            for (File fs : f.listFiles()) {
                listDelete(fs);
            }
        }
        System.out.println(f.getAbsolutePath());
        f.delete();
    }
}
